package com.work.demo.test;

import java.util.Optional;

/**
 * @author: deng
 */
public class Java8Tester {
	public static void main(String[] args) {
		Java8Tester tester = new Java8Tester();
		Integer value1 = null;
		Integer value2 = new Integer(10);

		// Optional.ofNullable - 允许传递为 null 参数
		Optional<Integer> a = Optional.ofNullable(value1);

		// Optional.of - 如果传递的参数是 null，抛出异常 NullPointerException
//		Optional<Integer> b = Optional.of(value1);
//		System.out.println(tester.sum(a,b));
		System.out.println(a.isPresent());
		String applicant = "LinYa1";
		String nodeKey = "LinYa2";
		String userName = "LinYa3";
		String password = "LinYa4";
		String sdsd = "LinYa5";
		String format = String.format("你的【%s】体验账号已开通，用户名：%s，密码：%s，请立即前往处理，协助完成测试回归任务！访问地址：%s", nodeKey, userName, password, sdsd);
		System.out.println(format);
//		System.out.println(b);
	}

	public Integer sum(Optional<Integer> a, Optional<Integer> b) {

		// Optional.isPresent - 判断值是否存在

		System.out.println("第一个参数值存在: " + a.isPresent());
		System.out.println("第二个参数值存在: " + b.isPresent());


		// Optional.orElse - 如果值存在，返回它，否则返回默认值
		Integer value1 = a.orElse(new Integer(0));

		//Optional.get - 获取值，值需要存在
		Integer value2 = b.get();
		return value1 + value2;
	}
}
